package com.avengers.common.bean.enums;

import com.avengers.core.bean.enums.RegistrarCode;
import com.avengers.core.kit.DateKit;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @author yu.wang
 * @since 1/4/23 10:01 AM
 **/
public enum VerisignCoupon2023 {
    season1(27800, LocalDate.of(2023, 1, 1), LocalDate.of(2023, 4, 1)),
    season2(29292, LocalDate.of(2023, 4, 1), LocalDate.of(2023, 7, 1)),
    season3(50672, LocalDate.of(2023, 7, 1), LocalDate.of(2023, 10, 1)),
    season4(31704, LocalDate.of(2023, 10, 1), LocalDate.of(2024, 1, 1));

    public final Integer total;
    public final Date startTime;
    public final Date endTime;
    private final LocalDate localStartDate;
    private final LocalDate localEndDate;

    public final static String USER_ID = "1919";
    /**
     * 2023 Season 1 价格
     */
    public final static BigDecimal PRICE = BigDecimal.valueOf(44);
    /**
     * 支持接口
     */
    public final static List<RegistrarCode> REGISTRAR_LIST = Arrays.asList(RegistrarCode.hzbest, RegistrarCode.seventd, RegistrarCode.dom1lim, RegistrarCode.dom2lim, RegistrarCode.dom3lim, RegistrarCode.dom4lim);

    VerisignCoupon2023(Integer total, LocalDate localStartDate, LocalDate localEndDate) {
        this.total = total;
        this.localStartDate = localStartDate;
        this.startTime = DateKit.fromLocalDate(localStartDate.atStartOfDay());
        this.localEndDate = localEndDate;
        this.endTime = DateKit.fromLocalDate(localEndDate.atStartOfDay().minusSeconds(1));
    }

    public static VerisignCoupon2023 of(LocalDate checkDate) {
        if (null == checkDate) {
            return null;
        }
        for (VerisignCoupon2023 coupon : values()) {
            if (coupon.localStartDate.isAfter(checkDate)) {
                continue;
            }
            if (coupon.localEndDate.isAfter(checkDate)) {
                return coupon;
            }
        }
        return null;
    }
}
